<?php
/**
 * Created by 豆豆.
 * mail longrbl@163.com
 * User: Administrator
 * Date: 2018/1/15
 * Time: 14:29
 */

namespace style\lib;


class Task_request
{
  public $service = '';
  public $data = '';
  public $task_service = '';

  function __construct($data, $service, $task_service)
  {
    $this->service = $service;
    $this->data = $data;
    $this->task_service = $task_service;
  }

  /** 控制器解析
   * @param $data json格式
   */
  function run()
  {
    try {
      $data = json_decode($this->data, true);
      if (empty($data['controller'])) {
        throw new \Exception('TASK控制器的方法为空!不能初始化');
      }
      $class_new = $data['controller'];
      $action = $data['action'];
      $task_data = array_merge($data['data'], array('task_time' => $data['time']));
      $ctlr_class = new $class_new($task_data, $this->service, $this->task_service);
      $ctlr_class->$action();
    } catch (\Exception $e) {
      throw new \Exception($e->getMessage());
    }

  }

}